package com.wqiuqiu.gulimallsearch.controller;


import com.wqiuqiu.common.R;
import com.wqiuqiu.common.excption.BizCodeEnume;
import com.wqiuqiu.common.to.es.SkuEsModel;
import com.wqiuqiu.gulimallsearch.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("product/save")
public class ProductController {

    @Autowired
    ProductService productService;

    @PostMapping("/up")
    public R productUp(@RequestBody List<SkuEsModel> skuEsModels) {
        boolean b;
        try {
            b = productService.productUp(skuEsModels);
        }catch (Exception e){
            return R.error(BizCodeEnume.PRODUCR_UP_EXCEPTION.getCode(),BizCodeEnume.PRODUCR_UP_EXCEPTION.getMessage());
        }
        if (b) {
            return R.ok();
        }else {
            return R.error("上架失败！！！");
        }
    }

}
